import PerfectScrollbar from 'perfect-scrollbar'
import 'perfect-scrollbar/css/perfect-scrollbar.css'

/**
 * 配置参数为perfectscrollbar的配置参数，通过指令的值传入
 */
export default {
    inserted (el, binding, vnode) {
        if (!el.scrollbar) {
            el.scrollbar = new PerfectScrollbar(el, binding.value)
            el.getElementsByClassName('ps__rail-x')[0].style.zIndex = 1000
            el.getElementsByClassName('ps__rail-y')[0].style.zIndex = 1000
        }
    },
    update (el) {
        if (!el.scrollbar) {
            el.scrollbar = new PerfectScrollbar(el)
        } else {
            el.scrollbar.update()
        }
    },
    componentUpdated (el) {
        if (!el.scrollbar) {
            el.scrollbar = new PerfectScrollbar(el)
        } else {
            el.scrollbar.update()
        }
    },
    unbind (el) {
        if (el.scrollbar) {
            el.scrollbar.destroy()
            delete el.scrollbar
        }
    }
}